/* 
 * BaseEntity.java
 * 
 * Data de criação: 04/09/2010
 * 
 * O2SOLUTIONS - SOLUÇÕES EM TECNOLOGIA DA INFORMAÇÃO. 
 *
 */
package br.com.o2solutions.core.integration.repository.entity;

import java.io.Serializable;

/**
 * Classe responsável por abstrair as entidades base.
 * 
 * @author Osvaldeir
 * @since 04/09/2010
 * 
 */
public abstract class BaseEntity<ID> implements Serializable{

	private static final long serialVersionUID = 1L;
	protected ID id;

	/**
	 * Retorna o(a) id.
	 * 
	 * @return ID
	 */
	public ID getId() {
		return id;
	}

	/**
	 * Atribui o(a) id.
	 * 
	 * @param id
	 *            ID
	 */
	public void setId(ID id) {
		this.id = id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	@SuppressWarnings("rawtypes")
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BaseEntity other = (BaseEntity) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(this.getClass().getName());
		builder.append(":");
		builder.append(this.getId());
		return builder.toString();
	}
}
